package com.coolw.dynamic.thread.pool.context;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 自定义线程池拒绝策略
 *
 * @author coolw
 * @date 2024/5/21 17:06
 */
@Slf4j
public class CustomRejectedExecutionPolicy implements RejectedExecutionHandler {

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        log.warn("CustomRejectedExecutionPolicy......");
        // 自定义线程池拒绝策略逻辑代码,继续执行一次任务
        if (!executor.isShutdown()) {
            r.run();
        }
    }
}
